package com.woniuxy.controller;

import com.woniuxy.model.Parking;
import com.woniuxy.result.Result;
import com.woniuxy.service.ParkingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("parking")
public class ParkingController {

    @Autowired
    private ParkingService parkingServiceimpl;

    @PostMapping("insert")
    public Result add(@RequestBody Parking parking){
        parkingServiceimpl.addParking(parking);
        return Result.success().msg("添加停车信息成功");
    }

    @DeleteMapping("delete/{id}")
    public Result deleteByIds(@PathVariable Integer id){
        parkingServiceimpl.deleteBatch(id);
        return Result.success().msg("删除成功");
    }

    @PutMapping("update")
    public Result updateById(@RequestBody Parking parking){
        parkingServiceimpl.updateById(parking);
        return Result.success().msg("修改信息成功");
    }

    @GetMapping("page/{curentpage}/{size}")
    public Result page(@PathVariable Integer curentpage,@PathVariable Integer size){
        List<Parking> parkings = parkingServiceimpl.pageQuery(curentpage,size);
        return Result.success(parkings).msg("分页查询成功");
    }
}
